1. Field of the Invention
This invention relates generally to managing references to software structures. The present invention relates more specifically to resetting references to software structures after the software structures have been deleted. The invention is more specifically related to providing a registry of references to a software structure for ease of update of the references when the referenced software structure is deleted. The invention is also related to providing a registry of references to a software object for ease of update of the references when the referenced software object is deleted. The invention is further related to a method, system, computer program product, memory, and object-oriented system for providing a registry of users of a software object for ease of updating the users when the referenced software object is deleted.
2. Discussion of the Background
Object Oriented Programming ("OOP") is a programming methodology in which a program is viewed as a collection of discrete objects that are self-contained collections of data structures and routines that interact with other objects. Many high-level languages, including C++, support the declaration of a class. The class is typically a template or detailed description of the objects or instances of objects which will be created or instantiated by a constructor function during program execution and destroyed by a destructor function when the object is no longer needed. A conversational reference to a class includes all of the objects currently in existence as a result of constructor calls. A class is made up of data items, structures, and methods. Data items correspond to variables of prior programming art. Structures are named groupings of related data items and other structures. Methods correspond to functions and subroutines of prior programming art.
An object-oriented framework is a reusable basic design structure, having abstract and concrete classes, that assists in building applications.
The three main features of object oriented programming are inheritance, encapsulation, and polymorphism. Inheritance allows a programmer to establish a general class, or a base class, with features which are desirable for a wide range of objects. For example, if a programmer designs a class polygon having certain features such as a closed convex shape made up of plural straight lines joined pairwise at vertices, it is then possible to construct polygon subclasses such as triangles, quadrilaterals, pentagons, and hexagons, all having the shared properties of the parent class polygon, with additional constraints on the number of sides to be allowed for the objects generated. It is also possible, for example, to have subclasses of class quadrilateral such as rectangle and rhombus. The class polygon is considered a base class, in that instantiations of actual objects is performed in its subclasses. However, the class polygon establishes certain properties inherent to all of the subclasses for inheritance purposes.
Encapsulation and polymorphism have already been described, and are already well known, in patents relating to object-oriented systems. A comprehensive discussion of OOP is provided in Coad, P. and Yourdon, E., Object-Oriented Analysis, Second Edition, Prentice-Hall, Inc., New Jersey, 1991, and in Booch, G., Object-Oriented Analysis and Design with Applications, Second Edition, Addison Wesley Longman, California, 1994, which are incorporated herein by reference.
A string variable or a string literal is a data structure composed of a sequence of characters of the character set of a particular application. A null string, a nil string, or an empty string is a string which contains no characters.
Pointers and references in programming languages are data items having values that are equivalent to absolute computer memory addresses. In many high-level programming languages, pointers are used to hold addresses of the first addressable unit of dynamically allocated computer memory. Computer memory is dynamically allocated for both data and instructions during compilation, loading, and execution of a program. For this invention, a software structure is an addressable collection of one or more software elements comprising data and/or instructions. Individual elements of a software structure are stored contiguously in some implementations, or are alternatively stored in non-contiguous storage locations, with references used to access the individual elements.
If plural pointers, for example, have their values set to reference a particular instance of a software structure, and the software structure is deleted, the pointers typically no longer reference valid data or instructions for the current application. Applications typically are partitioned to have plural modules having interfaces for inter-module communication. For this invention, a module is a collection of routines and/or data structures that performs a particular task or implements a particular abstract data type. If the exemplary plural pointers discussed above exist in different modules, it is difficult to examine the pointers for validity before use. Use of a pointer that is no longer valid, for example, as a result of deletion of the referenced software structure, frequently causes a computer system crash.
A reference counting technique in the related art involves allocation of storage for a numeric counter value with a reference to a newly allocated software structure whenever a software structure is requested which allows plural users of the software structure. Referencing the software structure during program execution involves referencing the counter. The counter is incremented by a value of one each time a new user establishes access to the software structure. The counter is decremented by a value of one each time a user relinquishes access to the software structure. When the counter value becomes zero, the software structure is deleted, as the software structure is no longer needed when it has no users. A complete description of the related art reference count structure is provided in Meyers, S., More Effective C++, Addison Wesley Longman, Inc., Massachusetts, 1996, which is incorporated herein by reference.
The reference counting technique is utilized to track the number of users of a software object. One reason for using reference counting techniques is to eliminate redundant storage. In computer programming languages such as C and C++, a reference to a character string literal is a pointer to the first character in the string. In some implementations, plural references to the same literal character string leads to excessive redundancy of the same values stored in computer memory.
In other implementations, a compiler recognizes the value of a character string as it parsed, creates the string, stores it in computer memory, and associates the address of the string with references to the string for users of the string. As users dynamically relinquish reference to the string, a used string must remain in existence until every user of the string relinquishes reference to the string. The reference counting technique establishes a counter of the current number of users of a particular software structure. As new users of a software structure reference the software structure, the counter is incremented to reflect the total number of users of the software structure. As software structures are updated to no longer reference the used software structure, the reference value is decremented to reflect the current number of users of the used software structure. When the reference counter reaches a value of zero, the used software structure is deleted, freeing up computer memory for other uses. If a system needs to delete the used software structure while there exists at least one user of the used software structure, there is no easy way to inform users of the deletion of the used software structure that it is being deleted.
FIGS. 1A and 1B illustrate an exemplary reference counting scheme. FIG. 1A illustrates an exemplary reference counting scheme with a single USED OBJECT 40, a REFERENCE COUNT in a REFERENCE COUNTED OBJECT 38, and four user objects USER 1 object 30, USER 2 object 32, USER 3 object 34, and USER 4 object 36. The REFERENCE COUNT 38 contains a value of 4, reflecting a total of four user objects currently using the USED OBJECT 40. Arrows from each of the user objects to the REFERENCE COUNTED OBJECT 38 denote pointers from each user object to the REFERENCE COUNTED OBJECT 38. An arrow from the REFERENCE COUNT 38 to the USED OBJECT 40 denotes a pointer to the USED OBJECT 40.
FIG. 1B illustrates the same reference counting scheme as shown in FIG. 1A, with only the USER 1 object 30 using the USED OBJECT 40. The USER 2 object 32, USER 3 object 34, and USER 4 object 36 of FIG. 1A are no longer users of the USED OBJECT 40, and the REFERENCE COUNT 38 contains a value of 1, reflecting three fewer users of the USED OBJECT 40 than in FIG. 1A. If the USER 1 object 30 relinquishes access to the USED OBJECT 40, the REFERENCE COUNT 38 is updated to contain a value of zero, signifying that there are no current users of the USED OBJECT 40, and that the USED OBJECT 40 is a candidate for deletion.
Using the reference counting technique, if the referenced software structure is deleted when the counter value is zero, the storage for the referenced software structure is typically returned to the operating system for other uses.
If a user who has not relinquished access to the software structure executes instructions to access the software structure after it is deleted, the results would be unpredictable, but would likely lead to addressability errors and a system crash. The reference counting technique ensures that the used object exists as long as at least one user of the object exists. However, situations exist wherein a system needs to delete a used object and reset all user references to the used object to reflect deletion of the used object for safety. In such cases, the reference counting technique is not appropriate.